package com.rjpacket.supernews.app.task;

import android.content.Context;
import android.os.AsyncTask;
import android.widget.ListView;
import android.widget.TextView;
import com.rjpacket.supernews.app.R;
import com.rjpacket.supernews.app.adapter.DuanziAdapter;
import com.rjpacket.supernews.app.model.Duanzi;
import com.rjpacket.supernews.app.tasks.DetailTaskCallOnBack;
import com.rjpacket.supernews.app.utils.HttpTool;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by WIN7 on 2015/3/10.
 */

/**
 * 段子内容加载的异步任务
 */
public class DuanziDetailTask extends AsyncTask<String, Integer, String> {

    private DetailTaskCallOnBack back;

    public DuanziDetailTask(DetailTaskCallOnBack back) {
        this.back = back;
    }

    private String position;
    private String url;

    @Override
    protected String doInBackground(String... params) {
        String ret = null;
        if (params != null && params.length > 0) {
            url = params[0];
            position = params[1];
        }

        byte[] bytes = HttpTool.get(url);
        if (bytes != null) {
            String str = new String(bytes);
            try {
                ret = str;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        return ret;
    }

    @Override
    protected void onPostExecute(String s) {

        if (s != null) {
            back.callBack(s, position);
        } else {
            back.callBack(null, null);
        }
    }
}
